package org.sao.geteway.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.sao.geteway.service.PermissionService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;
import org.springframework.util.AntPathMatcher;

import com.xiaoleilu.hutool.util.CollectionUtil;





/**
 * @author zhangyang
 *判断请求是否有权限
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {
	
	//做Urls匹配
	private AntPathMatcher antPathMatcher=new AntPathMatcher();

	@Override
	public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
		// TODO Auto-generated method stub
		Object principal=authentication.getPrincipal();
		List<GrantedAuthority> grantedAuthorityList=(List<GrantedAuthority>) authentication.getAuthorities();
		boolean hasPermission = false;
		
		if(principal!=null){
			if(CollectionUtil.isEmpty(grantedAuthorityList)){
				return hasPermission;
			}
			return true;
		}
		return hasPermission;
	}

}
